<template>
	<div class="diy_edit page_expert_participation" id="expert_participation_edit">
		<div class='warp'>
			<div class='container'>
				<div class='row diy_edit_content_box'>
						<div v-if="$check_field('set','meeting_number') || $check_field('add','meeting_number') || $check_field('get','meeting_number')" class="form-item col-12 col-md-6">
						<div class="diy_title">
							<span>
								会议编号:
							</span>
						</div>
								<!-- 文本 -->
									<div class="diy_field diy_text">
							<input type="text" id="form_meeting_number" v-model="form['meeting_number']" placeholder="请输入会议编号" v-if="(form['meeting_number'] && $check_field('set','meeting_number')) || (!form['meeting_number'] && $check_field('add','meeting_number'))"  :disabled="disabledObj['meeting_number_isDisabled']"/>
							<span v-else-if="$check_field('get','meeting_number')">{{ form['${obj.name}'] }}</span>
						</div>
										</div>
							<div v-if="$check_field('set','conference_name') || $check_field('add','conference_name') || $check_field('get','conference_name')" class="form-item col-12 col-md-6">
						<div class="diy_title">
							<span>
								会议名称:
							</span>
						</div>
								<!-- 文本 -->
									<div class="diy_field diy_text">
							<input type="text" id="form_conference_name" v-model="form['conference_name']" placeholder="请输入会议名称" v-if="(form['conference_name'] && $check_field('set','conference_name')) || (!form['conference_name'] && $check_field('add','conference_name'))"  :disabled="disabledObj['conference_name_isDisabled']"/>
							<span v-else-if="$check_field('get','conference_name')">{{ form['${obj.name}'] }}</span>
						</div>
										</div>
							<div v-if="$check_field('set','meeting_type') || $check_field('add','meeting_type') || $check_field('get','meeting_type')" class="form-item col-12 col-md-6">
						<div class="diy_title">
							<span>
								会议类型:
							</span>
						</div>
								<!-- 文本 -->
									<div class="diy_field diy_text">
							<input type="text" id="form_meeting_type" v-model="form['meeting_type']" placeholder="请输入会议类型" v-if="(form['meeting_type'] && $check_field('set','meeting_type')) || (!form['meeting_type'] && $check_field('add','meeting_type'))"  :disabled="disabledObj['meeting_type_isDisabled']"/>
							<span v-else-if="$check_field('get','meeting_type')">{{ form['${obj.name}'] }}</span>
						</div>
										</div>
							<div v-if="$check_field('set','meeting_time') || $check_field('add','meeting_time') || $check_field('get','meeting_time')" class="form-item col-12 col-md-6">
						<div class="diy_title">
							<span>
								会议时间:
							</span>
						</div>
								<!-- 文本 -->
									<div class="diy_field diy_text">
							<input type="text" id="form_meeting_time" v-model="form['meeting_time']" placeholder="请输入会议时间" v-if="(form['meeting_time'] && $check_field('set','meeting_time')) || (!form['meeting_time'] && $check_field('add','meeting_time'))"  :disabled="disabledObj['meeting_time_isDisabled']"/>
							<span v-else-if="$check_field('get','meeting_time')">{{ form['${obj.name}'] }}</span>
						</div>
										</div>
							<div v-if="$check_field('set','meeting_venue') || $check_field('add','meeting_venue') || $check_field('get','meeting_venue')" class="form-item col-12 col-md-6">
						<div class="diy_title">
							<span>
								会议地点:
							</span>
						</div>
								<!-- 文本 -->
									<div class="diy_field diy_text">
							<input type="text" id="form_meeting_venue" v-model="form['meeting_venue']" placeholder="请输入会议地点" v-if="(form['meeting_venue'] && $check_field('set','meeting_venue')) || (!form['meeting_venue'] && $check_field('add','meeting_venue'))"  :disabled="disabledObj['meeting_venue_isDisabled']"/>
							<span v-else-if="$check_field('get','meeting_venue')">{{ form['${obj.name}'] }}</span>
						</div>
										</div>
							<div v-if="$check_field('set','amount_of_participation') || $check_field('add','amount_of_participation') || $check_field('get','amount_of_participation')" class="form-item col-12 col-md-6">
						<div class="diy_title">
							<span>
								参会金额:
							</span>
						</div>
								<!-- 数字 -->
						<div class="diy_field diy_number">
							<input type="number" id="form_amount_of_participation" v-model.number="form['amount_of_participation']" placeholder="请输入参会金额" v-if="(form['amount_of_participation'] && $check_field('set','amount_of_participation')) || (!form['amount_of_participation'] && $check_field('add','amount_of_participation'))" :disabled="disabledObj['amount_of_participation_isDisabled']" />
							<span v-else-if="$check_field('get','amount_of_participation')">{{ form['${obj.name}'] }}</span>
						</div>
							</div>
							<div v-if="$check_field('set','participating_experts') || $check_field('add','participating_experts') || $check_field('get','participating_experts')" class="form-item col-12 col-md-6">
						<div class="diy_title">
							<span>
								参会专家:
							</span>
						</div>
						<div class="diy_field diy_down">
							<select id="form_participating_experts" :disabled="disabledObj['participating_experts_isDisabled']" v-model="form['participating_experts']" v-if="(form['participating_experts'] && $check_field('set','participating_experts')) || (!form['participating_experts'] && $check_field('add','participating_experts'))" >
								<option v-for="o in list_user_participating_experts" :value="o['user_id']">
									{{o['nickname'] + '-' + o['username']}}
								</option>
							</select>
							<span v-else-if="$check_field('get','participating_experts')">{{ form['participating_experts'] }}</span>
						</div>
					</div>
							<div v-if="$check_field('set','expert_name') || $check_field('add','expert_name') || $check_field('get','expert_name')" class="form-item col-12 col-md-6">
						<div class="diy_title">
							<span>
								专家姓名:
							</span>
						</div>
								<!-- 文本 -->
									<div class="diy_field diy_text">
							<input type="text" id="form_expert_name" v-model="form['expert_name']" placeholder="请输入专家姓名" v-if="(form['expert_name'] && $check_field('set','expert_name')) || (!form['expert_name'] && $check_field('add','expert_name'))"  :disabled="disabledObj['expert_name_isDisabled']"/>
							<span v-else-if="$check_field('get','expert_name')">{{ form['${obj.name}'] }}</span>
						</div>
										</div>
							<div v-if="$check_field('set','accommodation_or_not') || $check_field('add','accommodation_or_not') || $check_field('get','accommodation_or_not')" class="form-item col-12 col-md-6">
						<div class="diy_title">
							<span>
								是否住宿:
							</span>
						</div>
								<!-- 选项 -->
						<div class="diy_field diy_down">
							<select id="form_accommodation_or_not" v-model="form['accommodation_or_not']" v-if="(form['accommodation_or_not'] && $check_field('set','accommodation_or_not')) || (!form['accommodation_or_not'] && $check_field('add','accommodation_or_not'))" >
								<option v-for="o in list_accommodation_or_not" :value="o">
									{{o}}
								</option>
							</select>
							<span v-else-if="$check_field('get','accommodation_or_not')">{{ form['accommodation_or_not'] }}</span>
						</div>
							</div>
	


					<div v-if="user_group === '管理员' || $check_examine()" class="form-item col-12 col-md-6">
						<div class="diy_title">
							<span>
								审核状态:
							</span>
						</div>
						<div class="diy_field diy_select" v-if="$check_action('/expert_participation/edit','examine')">
							<!--<span> {{ form['examine_state'] }} </span>-->
							<select v-model="form['examine_state']">
								<option value="未审核">
									未审核
								</option>
								<option value="已通过">
									已通过
								</option>
								<option value="未通过">
									未通过
								</option>
							</select>
						</div>
						<div class="diy_field diy_text" v-else>
							<span>
								{{ form['examine_state'] }}
							</span>
						</div>
					</div>
					<div v-if="user_group === '管理员' || $check_examine()" class="form-item col-12 col-md-6">
						<div class="diy_title">
							<span>
								审核回复:
							</span>
						</div>
						<div class="diy_field diy_desc" v-if="$check_action('/expert_participation/edit','examine')">
							<textarea v-model="form['examine_reply']"></textarea>
						</div>
						<div class="diy_field diy_text" v-else>
							<span>
								{{ form['examine_reply'] }}
							</span>
						</div>
					</div>


				</div>
				<div class="diy_edit_submit_box row">
					<div class="col-12">
						<div class="btn_box">
							<button class="btn_submit" @click="submit()">提交</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import mixin from "@/mixins/page.js";
	export default {
		mixins: [mixin],
		components: {},
		data() {
			return {
				url_get_obj: "~/api/expert_participation/get_obj?",
				url_add: "~/api/expert_participation/add?",
				url_set: "~/api/expert_participation/set?",

				// 登录权限
				oauth: {
					"signIn": true,
					"user_group": []
				},

				// 查询条件
				query: {
						"meeting_number": "",
							"conference_name": "",
							"meeting_type": "",
							"meeting_time": "",
							"meeting_venue": "",
							"amount_of_participation": 0,
							"participating_experts": 0,
							"expert_name": "",
							"accommodation_or_not": "",
						"expert_participation_id": 0,
				},

				obj: {
						"meeting_number":  '', // 会议编号
							"conference_name":  '', // 会议名称
							"meeting_type":  '', // 会议类型
							"meeting_time":  '', // 会议时间
							"meeting_venue":  '', // 会议地点
							"amount_of_participation":  0, // 参会金额
							"participating_experts": 0, // 参会专家
							"expert_name":  '', // 专家姓名
							"accommodation_or_not":  '', // 是否住宿
						"examine_state": "未审核",
					"examine_reply": "",
					"expert_participation_id": 0,
				},

				// 表单字段
				form: {
						"meeting_number":  '', // 会议编号
							"conference_name":  '', // 会议名称
							"meeting_type":  '', // 会议类型
							"meeting_time":  '', // 会议时间
							"meeting_venue":  '', // 会议地点
							"amount_of_participation":  0, // 参会金额
							"participating_experts": 0, // 参会专家
							"expert_name":  '', // 专家姓名
							"accommodation_or_not":  '', // 是否住宿
						"examine_state": "未审核",
					"examine_reply": "",
					"expert_participation_id": 0,
				},
				disabledObj:{
						"meeting_number_isDisabled": false,
							"conference_name_isDisabled": false,
							"meeting_type_isDisabled": false,
							"meeting_time_isDisabled": false,
							"meeting_venue_isDisabled": false,
									"participating_experts_isDisabled": false,
							"expert_name_isDisabled": false,
							"accommodation_or_not_isDisabled": false,
					},

																		// 用户列表
				list_user_participating_experts: [],
								// 是否住宿选项列表
				list_accommodation_or_not: ['是','否'],
		
				// ID字段
				field: "expert_participation_id",

			}
		},
		methods: {
			
				
				
				
				
				
						/**
			 * 获取专家用户用户列表
			 */
			async get_list_user_participating_experts() {
				// if(this.user_group !== "管理员" && this.form["participating_experts"] === 0) {
				//     this.form["participating_experts"] = this.user.user_id;
				// }
				var json = await this.$get("~/api/user/get_list?user_group=专家用户");
				if(json.result && json.result.list){
					this.list_user_participating_experts = json.result.list;
				}
				else if(json.error){
					console.error(json.error);
				}
			},
					async get_user_session_participating_experts(){
				var _this = this;
				var json = await this.$get("~/api/user_group/get_obj?name=专家用户");
				if(json.result && json.result.obj){
					var source_table = json.result.obj.source_table;
					var user_id = _this.$store.state.user.user_id;
					if (user_id){
						var url = "~/api/"+source_table+"/get_obj?"
						this.$get(url, {"user_id":_this.$store.state.user.user_id}, function(res) {
							if (res.result && res.result.obj) {
								var arr = []
								for (let key in res.result.obj) {
									arr.push(key)
								}
								var arrForm = []
								for (let key in _this.form) {
									arrForm.push(key)
								}
								_this.form["participating_experts"] = user_id
								_this.disabledObj['participating_experts' + '_isDisabled'] = true
								for (var i=0;i<arr.length;i++){
                  if (arr[i]!=='examine_state' && arr[i]!=='examine_reply') {
                    for (var j = 0; j < arrForm.length; j++) {
                      if (arr[i] === arrForm[j]) {
                        if (arr[i] !== "participating_experts") {
                          _this.form[arrForm[j]] = res.result.obj[arr[i]]
                          _this.disabledObj[arrForm[j] + '_isDisabled'] = true
                          break;
                        }
                      }
                    }
                  }
								}
							}
						});
					}
				}
				else if(json.error){
					console.error(json.error);
				}
			},
	
				
				
	
			/**
			 * 修改文件
			 * @param { Object } files 上传文件对象
			 * @param { String } str 表单的属性名
			 */
			change_file(files, str) {
				var form = new FormData();
				form.append("file", files[0]);
				this.$post("~/api/expert_participation/upload?", form, (res) => {
					if (res.result) {
						this.form[str] = res.result.url;
					} else if (res.error) {
						this.$toast(res.error.message);
					}
				});
			},

			/**
			 * 获取对象后获取缓存表单
			 * @param {Object} json
			 * @param {Object} func
			 */
			get_obj_before(param){
				var form = $.db.get("form");
				// if (form) {
        //   delete(form.examine_state)
        //   delete(form.examine_reply)
        //   this.obj = $.push(this.obj ,form);
				// 	this.form = $.push(this.form ,form);
				// }
				// var arr = []
				// for (let key in form) {
				// 	arr.push(key)
				// }
				// for (var i=0;i<arr.length;i++){
				// 	this.disabledObj[arr[i] + '_isDisabled'] = true
				// }
        if (form) {
          var arr = []
          for (let key in form) {
            arr.push(key)
          }
          var arrForm = []
          for (let key in this.form) {
            arrForm.push(key)
          }
          for (var i=0;i<arr.length;i++){
            if (arr[i]!=='examine_state' && arr[i]!=='examine_reply') {
              for (var j = 0; j < arrForm.length; j++) {
                if (arrForm[j] === arr[i]) {
                  this.form[arrForm[j]] = form[arr[i]]
                  this.obj[arrForm[j]] = form[arr[i]]
                  this.disabledObj[arrForm[j] + '_isDisabled'] = true
                  break;
                }
              }
            }
          }
        }
																		
        $.db.del("form");
				return param;
			},

			/**
			 * 获取对象后获取缓存表单
			 * @param {Object} json
			 * @param {Object} func
			 */
			get_obj_after(json ,func){
				// var form = $.db.get("form");
				// var obj = Object.assign({} ,form ,this.obj);
				// if (obj) {
        //   delete(obj.examine_state)
        //   delete(obj.examine_reply)
				// 	this.obj = $.push(this.obj ,obj);
				// }
				// if (form) {
        //   delete(form.examine_state)
        //   delete(form.examine_reply)
				// 	this.form = $.push(this.form ,form);
				// }
				if(func){
					func(json);
				}
			},

		},
		created() {
																							this.get_user_session_participating_experts();
					this.get_list_user_participating_experts();
									},
	}
</script>

<style>




</style>
